#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
/*
//蛇形矩阵
void generateSnakeMatrix(int n, int matrix[n][n]) {
    int value = 1;
    int row = 0, col = 0;
    int direction = 1; // 1 for right, -1 for left

    for (int i = 0; i < n; i++) {
        if (direction == 1) {
            for (int j = 0; j < n; j++) {
                matrix[row][col] = value++;
                col++;
            }
            col--;
        }
        else {
            for (int j = 0; j < n; j++) {
                matrix[row][col] = value++;
                col--;
            }
            col++;
        }
        row++;
        direction = -direction; // change direction
    }
}

void printMatrix(int n, int matrix[n][n]) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            printf("%3d ", matrix[i][j]);
        }
        printf("\n");
    }
}

int main() {
    int n;
    printf("请输入一个整数 n: ");
    scanf("%d", &n);

    int matrix[n][n];
    generateSnakeMatrix(n, matrix);
    printMatrix(n, matrix);

    return 0;
}
